package org.example.面向过程;

import com.mysql.cj.jdbc.Driver;

import java.sql.*;
import java.util.Scanner;
//修改
public class DemoB {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入性别");
        String sex = in.next();
        System.out.println("请输入年龄");
        int sge = in.nextInt();
        System.out.println("请输入ID");
        int id= in.nextInt();
        try {
            Class.forName(Driver.class.getName());
        }catch (ClassNotFoundException e){
            System.out.println("没有找到驱动！");
        }
        try {
            String url="jdbc:mysql://localhost:3306/bd200521?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
            String username = "root";
            String password = "a123456";
            Connection conn = DriverManager.getConnection(url,username,password);
            String sql = "update users set usersex='"+sex+"',userage="+sge+" where userid="+id+"";
            PreparedStatement ps = conn.prepareStatement(sql);
            int r = ps.executeUpdate();
            System.out.println(r);
            ps.close();
            conn.close();
        }catch (SQLException e){
            System.out.println(e.getMessage());
        }

    }
}
